package cn.edu.scau.cmi.hekaimin.Hibernate.controller;

import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;

import javafx.scene.control.ToggleGroup;
import javafx.stage.Stage;
import javafx.event.ActionEvent;

public class HibernateFXController {
	@FXML
	private TextField username;
	@FXML
	private TextField password;
	@FXML
	private Button btn_1;
	@FXML
	private ToggleGroup status;
	@FXML
	private RadioButton student;
	@FXML
	private RadioButton teacher;
	
	private Stage stage;
     public void init(Stage stage) {
    	 student.setUserData("学生");
    	 teacher.setUserData("教师");
    	 this.stage = stage;
     }
	// Event Listener on Button[#btn_1].onAction
	@FXML
	public void loading(ActionEvent event) {
		
		if(username.getText().equals("") || password.getText().equals("")) {
			Alert alert = new Alert(AlertType.WARNING);
			alert.setTitle("Warning");
			alert.setContentText("账号或密码不能为空,请重新输入");
			alert.showAndWait();
		}else if(username.getText().equals("root")&&password.getText().equals("root")&&status.getSelectedToggle().getUserData().toString().equals("教师") ){
			    System.out.println("管理员登陆成功 跳转!");
			    RootFX fx = new RootFX();
			    stage.close();
		}else if(username.getText().equals("student")&&password.getText().equals("123")&&status.getSelectedToggle().getUserData().toString().equals("学生")){
			    System.out.println("学生登陆成功!");
			    StudentFX fx = new StudentFX();
			    stage.close();
		}else if(username.getText().equals("teacher")&&password.getText().equals("123")&&status.getSelectedToggle().getUserData().toString().equals("教师")) {
			    System.out.println("教师登陆成功!");
			    TeacherFX fx = new TeacherFX();
			    stage.close();
		}else {
			Alert alert = new Alert(AlertType.WARNING);
			alert.setTitle("Warning");
			alert.setContentText("账号或密码错误,请重新输入");
			alert.showAndWait();
		}
	}
}
